package cn.structure.edp;

import cn.structure.ClassEntity;
import cn.structure.MethodEntity;

import java.util.Objects;

public class Delegation extends EdpEntity {
    private ClassEntity delegator;
    private MethodEntity operation;
    private ClassEntity delegate;
    private MethodEntity operation2;

    public Delegation(ClassEntity delegator, MethodEntity operation, ClassEntity delegate, MethodEntity operation2) {
        super();
        this.delegator = delegator;
        this.operation = operation;
        this.delegate = delegate;
        this.operation2 = operation2;
    }

    public enum Role {
        delegator, operation, delegate, operation2
    }

    public ClassEntity getDelegator() {
        return delegator;
    }

    public void setDelegator(ClassEntity delegator) {
        this.delegator = delegator;
    }

    public MethodEntity getOperation() {
        return operation;
    }

    public void setOperation(MethodEntity operation) {
        this.operation = operation;
    }

    public ClassEntity getDelegate() {
        return delegate;
    }

    public void setDelegate(ClassEntity delegate) {
        this.delegate = delegate;
    }

    public MethodEntity getOperation2() {
        return operation2;
    }

    public void setOperation2(MethodEntity operation2) {
        this.operation2 = operation2;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Delegation{\n\t");
        sb.append(super.toString());
        sb.append("\n\t\"delegator\":")
                .append(delegator);
        sb.append(",\n\t\"operation\":")
                .append(operation);
        sb.append(",\n\t\"delegate\":")
                .append(delegate);
        sb.append(",\n\t\"operation2\":")
                .append(operation2);
        sb.append("\n}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        Delegation that = (Delegation) o;
        return Objects.equals(delegator, that.delegator) &&
                Objects.equals(operation, that.operation) &&
                Objects.equals(delegate, that.delegate) &&
                Objects.equals(operation2, that.operation2);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), delegator, operation, delegate, operation2);
    }
}
